package com.cn.qtms.util.sms.submail;

import com.alibaba.fastjson.JSON;
import com.cn.qtms.util.HttpUtil;
import com.cn.qtms.util.sms.SmsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;
import java.util.Map;

/**
 * @Name:SubmailSmsUtil
 * @Description:
 * @Author: Neil
 * @Date: 2019-10-30 14:08
 **/
@Component
public class SubmailSmsUtil implements SmsUtil {

    private static final  String URL = "https://api.mysubmail.com/message/xsend.json";

    @Autowired
    private HttpUtil httpUtil;

    @Autowired
    private Environment env;


    @Override
    public void sendSms(String phone, String verifyCode) throws Exception {

        HttpMethod method =  HttpMethod.POST;
        MultiValueMap<String, Object> map= new LinkedMultiValueMap<>();
        String appid= env.getProperty("submail.sms.appid");
        String signature= env.getProperty("submail.sms.signature");
        String project= env.getProperty("submail.sms.projectRegister");
        map.add("appid",appid);
        map.add("to",phone);
        map.add("project",project);
        map.add("signature",signature);
        map.add("vars",verifyCode);
        httpUtil.client(URL,method,map);
    }
}
